package com.bdmc.web.controller.report;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.page.TableDataInfo;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.report.domain.bo.ReportPersonMilesBo;
import com.bdmc.report.domain.vo.ReportPersonMilesVo;
import com.bdmc.report.service.IReportPersonMilesService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;


/**
 * 工作时间距离统计控制器
 *
 * @author bdmc
 * @date 2022-08-11
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/personMiles")
public class ReportPersonMilesController extends BaseController {

    private final IReportPersonMilesService iReportPersonMilesService;

    /**
     * 查询工作时间距离统计列表
     */
    @SaCheckPermission("report:personMiles:list")
    @GetMapping("/list")
    public TableDataInfo<ReportPersonMilesVo> list(@Validated(QueryGroup.class) ReportPersonMilesBo bo, PageQuery pageQuery) {
        return iReportPersonMilesService.mySelectPage(bo, pageQuery);
    }

    /**
     * 导出工作时间距离统计列表
     */
    @SaCheckPermission("report:personMiles:export")
    @Log(title = "工作时间距离统计", businessType = BusinessType.EXPORT)
    @PostMapping("/ex`port")
    public void export(@Validated ReportPersonMilesBo bo, HttpServletResponse response) {
        List<ReportPersonMilesVo> list = iReportPersonMilesService.queryList(bo);
        ExcelUtil.exportExcel(list, "工作时间距离统计", ReportPersonMilesVo.class, response);
    }

    /**
     * 获取工作时间距离统计详细信息
     */
    @SaCheckPermission("report:personMiles:query")
    @GetMapping("/{personMilesId}")
    public AjaxResult<ReportPersonMilesVo> getInfo(@PathVariable("personMilesId") Long PersonMilesId) {
        return AjaxResult.success(iReportPersonMilesService.queryById(PersonMilesId));
    }

    /**
     * 新增工作时间距离统计
     */
    @SaCheckPermission("report:personMiles:add")
    @Log(title = "工作时间距离统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ReportPersonMilesBo bo) {
        return toAjax(iReportPersonMilesService.insertByBo(bo));
    }

    /**
     * 修改工作时间距离统计
     */
    @SaCheckPermission("report:personMiles:edit")
    @Log(title = "工作时间距离统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ReportPersonMilesBo bo) {
        return toAjax(iReportPersonMilesService.updateByBo(bo));
    }

    /**
     * 删除工作时间距离统计
     */
    @SaCheckPermission("report:personMiles:remove")
    @Log(title = "工作时间距离统计" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{personMilesIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] personMilesIds) {
        return toAjax(iReportPersonMilesService.deleteWithValidByIds(Arrays.asList(personMilesIds), true));
    }
}
